package user_api

import (
	"fmt"
	"gin_study_blog/common"
	"gin_study_blog/common/http"
	"gin_study_blog/models"

	"github.com/gin-gonic/gin"
)

func (UserApi) UserDeleteView(c *gin.Context) {
	var re models.RemoveRequest

	err := c.ShouldBindJSON(&re)
	if err != nil {
		http.FailWithCode(http.ParamsError, c)
		return
	}

	userList := make([]*models.UserModel, 0)
	count := common.DB.Find(&userList, re.IdList).RowsAffected
	if count == 0 {
		http.FailWithMessage("数据不存在", c)
		return
	}

	common.DB.Delete(&userList)
	http.IsOkWithMessage(fmt.Sprintf("共删除 %d 个用户", count), c)
}
